var scustomerId;
loadInitData();
function loadInitData() {
    var token = localStorage.getItem("token");
    console.log("token:"+token);
    $.ajax({
        type: "get",
        url: "/demo/XQing",
        headers: {'token': token},
        success: function (result) {
            var loginCustomer=result.data;
            console.log("==============")
            console.log(result.data)
            if(loginCustomer!=null){
                $(".head-user").hide();
                scustomerId=loginCustomer.customerId;
                console.log(scustomerId)
                var url ="/demo/order?customerId="+scustomerId;
                // $(".customerIdDZ").html('<span class="dianzanCUSTID">'+loginCustomerId+'</span>');
                $(".customerIdDZ").text(scustomerId)
                $(".user-menu").html('<li class="text"><a href='+url+'>个人中心</a></li>\n' +
                    '                 <li class="text" id="return"><button style="border: none">退出登录</button></li>');
                $(".user-info").show();
                getByAll();
            }else {
                $(".head-user").show();
                $(".user-info").hide();

            }
        }
    })
}



function getByAll(){
    var movieId=document.querySelector(".ssmovieId").textContent;
    console.log(scustomerId)
    console.log(movieId)
    $.ajax({
        type: "get",
        url: "../demo/recommendByMovie",
        data: {
            customerId : scustomerId,
            movieId : movieId
        },
        success: function(result){
            $(".movie-list").html("");
            console.log(result);
            for (var i =0;i<result.length;i++){
                console.log(result.length);
                var movieId = result[i].movieId;
                var movieCname =result[i].movieCname;
                var moviePicture = result[i].moviePicture;
                var movieEle =
                    "<li class=\"poster-item\" >\n" +
                    "                        <img class=\"img-wrap\" src=\"../demo/"+moviePicture+"\" alt=\"\">\n" +
                    "                        <span class=\"tetle-wrap\">"+movieCname+"</span>\n" +
                    "                        <a class=\"wrap\" href=\"../demo/MovieDetail?movieId="+movieId+"\">\n" +
                    "                            <div class=\"btn-wrap\">\n" +
                    "                                <span >查看详情</span>\n" +
                    "                            </div>\n" +
                    "                        </a>\n" +
                    "                        <a class=\"wrap\" href=\"../demo/movieSchedule?movieId="+movieId+"\">\n" +
                    "                            <div class=\"btn-wrap\">\n" +
                    "                                <span >立即购买</span>\n" +
                    "                            </div>\n" +
                    "                        </a>\n" +
                    "                    </li>"

                $(".movie-list").append(movieEle);
            }
        }
    })
}
